<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layout 后台大布局 - Layui</title>
    <link rel="stylesheet" href="../static/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <% include "../login/header.html" %>


    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <% include "../login/left.html" %>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
            <legend>历史数据</legend>
        </fieldset>
        <div style="padding: 10px;">
                <span class="layui-breadcrumb">
                    <a href="/">首页</a>
                    <a>设备管理  </a>
                    <a><cite>历史数据</cite></a>
                </span>
        </div>
        <div class="layui-form">
            <div class="layui-form-item" style="padding-top:5px">
                <div class="layui-inline">
                    <label class="layui-form-label">APP KEY</label>
                    <div class="layui-input-block">
                        <input type="text" name="app_key" placeholder="请输入appKey"
                               autocomplete="off"
                               class="layui-input"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="active" id="active">
                            <option value="">请选择</option>
                            <option value="1">启用</option>
                            <option value="0">禁用</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card">

            <div class="layui-card-body">
                <table class="layui-table" lay-skin="nob" lay-filter="history-version-manage" id="historyVersionTable">
                </table>
            </div>
            <script type="text/html" id="historyBar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
                {{# if(d.active==0){ }}
                <a class="layui-btn  layui-btn-xs" lay-event="enable"><i
                        class="layui-icon layui-icon-delete"></i>生效</a>
                {{# }if(d.active ==1) { }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="enable"><i
                        class="layui-icon layui-icon-delete"></i>失效</a>
                {{# }}}
            </script>
        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 底部固定区域
    </div>
</div>
<script src="../static/layui/layui.js"></script>
<script src="/static/js/jquery.min.js" media="all"></script>
<script src="../static/assets/js/global.js"></script>
<script>
    var table = '';
    layui.use(['common'], () => {
        table = layui.table;
        var element = layui.element;
        common = layui.common;
        form = layui.form;
        //监听工具条
        table.on('tool(history-version-manage)', function (obj) {
            var data = obj.data;
            if (obj.event === 'enable') {
                let type = data.active == 0 ? '生效' : '失效';
                layer.confirm(`真的要${type}该版本数据？`, function (index, layero) {
                    $.ajax({
                        url: '/historyVersion/enabled',
                        method: 'post',
                        data: {id: data.id, active: data.active},
                        success: (result) => {
                            if (result.errmsg == 1) {
                                layer.msg('修改成功！');
                                setTimeout(() => {
                                    table.reload('historyVersionTable'); //数据刷新
                                }, 1000);
                            } else {
                                layer.msg('修改失败！');
                            }
                            layer.close(index); //关闭弹层
                        }
                    });
                });
            } else {
                var resultMap;
                $.ajax({
                    url: '/historyVersion/getVersionConfig',
                    method: 'POST',
                    data: {id: data.id},
                    success: (result) => {
                        resultMap = result;
                    }
                });
                var index = layer.open({
                    type: 2
                    , title: '编辑信息'
                    , content: '/historyVersion/editPage'
                    , maxmin: true
                    , area: ['600px', '500px']
                    // , btn: ['关闭', '关闭']
                    , success: (layero, index) => {
                        layero.find('iframe').contents().find('#config_md5').val(resultMap.config_md5);
                        layero.find('iframe').contents().find('#base_line_md5').val(resultMap.base_line_md5);
                        layero.find('iframe').contents().find('#featrue_md5').val(resultMap.featrue_md5);
                        layero.find('iframe').contents().find('#id').val(resultMap.id);
                    }
                });
            }
        });
    });
    //JavaScript代码区域
    layui.use(['element', 'form'], function () {
        var element = layui.element;
        layui.form;
    });
    layui.config({
        base: '/static/layuiadmin/historyVersion'
    }).extend({
        fileVersionList: '/fileVersionListIndex', //主入口模块
    }).use(['fileVersionList'], function () {
    });
</script>
</body>
</html>
